@page "/docio/encrypt-and-decrypt"
@inject Microsoft.JSInterop.IJSRuntime JS
@using System.IO
@using Syncfusion.Blazor.Buttons
@using BlazorDemos.Data.FileFormats.DocIO
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment;
@inherits SampleBaseComponent;

<SampleDescription>
    <p style="font-size:16px">DocIO supports to encrypt a Word document with password that restrict others from accessing or modifying confidential contents. You can also open an encrypted Word document using DocIO with valid password.</p>
</SampleDescription>
<ActionDescription>
   <p style="font-size:16px">More information about the encrypt and decrypt options can be found in this <a href="https://help.syncfusion.com/file-formats/docio/working-with-security">documentation</a> section.</p>
</ActionDescription>

<div class="control-section">
    <p style="font-size:16px">Click the button to view the generated Word document. Please note that Microsoft Word Viewer or Microsoft Word is required to view the resultant Word document.</p>
    <table>
        <tr class="row">
            <td colspan="4" height="25px">
                <SfRadioButton Label="Encrypt Document" Name="Encrypt" Value=@("Encrypt") @bind-Checked="@Group1"></SfRadioButton>
            </td>
        </tr>
        <tr class="row">
            <td colspan="4" height="25px">
                <SfRadioButton Label="Decrypt Document" Name="Decrypt" Value=@("Decrypt") @bind-Checked="@Group1"></SfRadioButton>
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <div class="button-section">
                    <div id="button-control">
                        <div class="row">
                            <div>
                                <SfButton @onclick="GenerateDocument">Generate Document</SfButton>
                            </div>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
    </table>
</div>

<style>
    .control-section .row {
        margin: 10px 0;
    }
</style>

@code {
    MemoryStream documentStream;
    string Group1 = "Encrypt";
    /// <summary>
    /// Encrypt and decrypt and download the Word document
    /// </summary>
    public async Task GenerateDocument(MouseEventArgs args)
    {
        EncryptDecryptService service = new EncryptDecryptService(hostingEnvironment);
        documentStream = service.EncryptDecryptDocument(Group1);
        await JS.SaveAs("Encrypt and Decrypt.docx", documentStream.ToArray());
    }
}